package com.liuyuan.controller;

import com.liuyuan.pojo.Book;
import com.liuyuan.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/book")
public class BookController {
    @Autowired
    private BookService bookService;
    @RequestMapping("/getBookById")
    public Book getBookById(int id){
        Book book = bookService.getBookById(id);
        return book;
    }

    @RequestMapping("/getAllBook")
    public List<Book> getAllbook(){
        return bookService.getAllBook();

    }

    @RequestMapping("/insertBook")
    public int insertBook(@RequestBody Book book){
        return bookService.insertBook(book);
    }

    @RequestMapping ("/updateBook")
    public int updateBook(@RequestBody Book book){
        return bookService.updateBook(book);
    }

    @RequestMapping("/deleteBook")
    public int deleteBook(int id){
        return bookService.deleteBook(id);
    }
}
